package com.star.spring.deferred.service.completable;


import com.star.spring.deferred.utils.CommonUtils;

import java.util.concurrent.CompletableFuture;

/**
 * @description: 没有返回值的异步任务
 * @author: star
 * @create: 2024-12-22 00:58
 **/

public class RunAsyncDemo {

    public static void main(String[] args) {

        CommonUtils.log("主线程开始");

        // completableFuture创建一个线程跟创建一个Thread流程是一样的
        CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {

                CommonUtils.log("正在读取文件");
                CommonUtils.sleep(5);
                CommonUtils.log("读取文件完成");
            }
        });

        CommonUtils.sleep(3);
        CommonUtils.log("主线程结束");

    }
}
